/* eslint-disable */
(function () {
  var myurl = window.location.href;

  function GetRequest() {
    var e = location.href;
    var f = {};
    if (e.indexOf("?") != -1) {
      var g = e.substr(e.indexOf("?") + 1);
      g = g.split("&");
      for (var h = 0; h < g.length; h++) {
        f[g[h].split("=")[0]] = decodeURI(g[h].split("=")[1]);
      }
    }
    return f;
  }

  function shareNum() {
    $.ajax({
      type: 'get',
      url: 'http://wxjx.unisk.cn/wxjx/vr/common/share/updateShareNum',
      data: '',
      success: function (result) {}
    })
  }
  wx
    .ready(function () {
      var title = "快来助我一票得iPhone X！";
      var descT = "我是" + GetRequest().usernum + "号呦~";
      var desc = "快来为我(" + GetRequest().usernum + "号)助力得iPhone X、腾讯视频会员月卡等好礼！";
      var userid = '';
      if (Boolean(GetRequest().userid)) {
        userid = GetRequest().userid;
      }
      var link = 'http://wxjx.unisk.cn/wxjx/vr/common/share/toShare';
      var imgUrl = "http://wxjx.unisk.cn/pages/2019/wxjx/food/static/images/zhuozi.png";

      //分享到朋友圈
      wx.onMenuShareTimeline({
        title: title, // 分享标题【必填】
        desc: desc, // 分享描述【必填】
        link: link, // 分享链接【必填】
        imgUrl: imgUrl, // 分享图标【必填】
        success: function () {
          // 用户确认分享后执行的回调函数
          shareNum();
        },
        cancel: function () {
          // 用户取消分享后执行的回调函数
        }
      });

      //分享给好友
      wx.onMenuShareAppMessage({
        title: title, // 分享标题【必填】
        desc: descT, // 分享描述【必填】
        link: link, // 分享链接【必填】
        imgUrl: imgUrl, // 分享图标【必填】
        type: 'link', // 分享类型,music、video或link，不填默认为link【必填】
        dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
        success: function () {
          // 用户确认分享后执行的回调函数 alert('已分享');
          shareNum();
        },
        cancel: function () {
          // 用户取消分享后执行的回调函数 alert('已取消');
        }
      });

    });

  var appId = "wxf71dfa4539d2f215";
  var nonceStr = "oDxlNmsjqvV9D29r"; //随意
  var timestamp = "1420942347"; //随意

  var signature = null;

  $.ajax({
    url: 'http://wxjx.unisk.cn/weixinjx/WeiXinJxApi/getSignature',
    async: false,
    dataType: "json",
    data: {
      "nonceStr": nonceStr,
      "timestamp": timestamp,
      "url": myurl
    },
    success: function (data) {
      //console.log(data);
      signature = data.signature;
      //console.log(signature);
    },
    error: function () {
      signature = "error";
    }
  });
  wx.config({
    debug: true,
    appId: appId,
    timestamp: timestamp,
    nonceStr: nonceStr,
    signature: signature,
    jsApiList: [
      'checkJsApi',
      'onMenuShareTimeline',
      'onMenuShareAppMessage',
      'onMenuShareQQ',
      'onMenuShareWeibo',
      'hideMenuItems',
      'showMenuItems',
      'hideAllNonBaseMenuItem',
      'showAllNonBaseMenuItem',
      'translateVoice',
      'startRecord',
      'stopRecord',
      'onRecordEnd',
      'playVoice',
      'pauseVoice',
      'stopVoice',
      'uploadVoice',
      'downloadVoice',
      'chooseImage',
      'previewImage',
      'uploadImage',
      'downloadImage',
      'getNetworkType',
      'openLocation',
      'getLocation',
      'hideOptionMenu',
      'showOptionMenu',
      'closeWindow',
      'scanQRCode',
      'chooseWXPay',
      'openProductSpecificView',
      'addCard',
      'chooseCard',
      'openCard'
    ]
  });
})();